package salvarcasodetestes;

import entidadesparaguardardadosteste.CasoDeTeste;
import gui.DeclaracaoDeMetodo;

import interfaceusuario.TelaCriacaoDaSuiteDeTestes;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class TesteSerializar 
{
	public static void main(String args [])
	{
		 //create a Serializable List
		Method metodo = TelaCriacaoDaSuiteDeTestes.class.getMethods()[0];
		//String urlProjeto, String urlParaArquivoJavaQueTemOMetodo, String cabecalhoMetodo
		DeclaracaoDeMetodoSerializavel declaracaoDeMetodo = new DeclaracaoDeMetodoSerializavel("C:/Users/joao/Documents/eclipse new projets/ProjetoFormatacaoBugada", "C:/Users/joao/Documents/eclipse new projets/ProjetoFormatacaoBugada/src/p/ClasseFormBugada.java", "int somar(int x, int y)");
	    CasoDeTesteSerializavel quark = new CasoDeTesteSerializavel();
	    quark.setCasoDeTesteEstahCompleto(true);
	    quark.setIdCasoDeTeste(1);
	    quark.setMetodo(declaracaoDeMetodo);
	    quark.setNomeClasseAssociadaAoCasoDeTeste("ClasseFormBugada");
	    quark.setValoresDosParametrosDoMetodo(new LinkedList<Object>());
	    quark.setValorEsperadoDaSaida("3");
		
	    //serialize the List
	    //note the use of abstract base class references

	    try{
	      //use buffering
	      OutputStream file = new FileOutputStream( "quarks.txt" );
	      OutputStream buffer = new BufferedOutputStream( file );
	      ObjectOutput output = new ObjectOutputStream( buffer );
	      try{
	        output.writeObject(quark);
	      }
	      finally{
	        output.close();
	      }
	    }  
	    catch(IOException ex){
	      ex.printStackTrace();
	    }

	    //deserialize the quarks.ser file
	    //note the use of abstract base class references
	    
	    try{
	      //use buffering
	      InputStream file = new FileInputStream( "quarks.txt" );
	      InputStream buffer = new BufferedInputStream( file );
	      ObjectInput input = new ObjectInputStream ( buffer );
	      try{
	        //deserialize the List
	    	  CasoDeTesteSerializavel recoveredQuarks = (CasoDeTesteSerializavel)input.readObject();
	        //display its data
	        /*for(String quark: recoveredQuarks){
	          System.out.println("Recovered Quark: " + quark);
	        }*/
	        System.out.println("recovered object:" + recoveredQuarks.getMetodo().getCabecalhoDoMetodo());
	      }
	      finally{
	        input.close();
	      }
	    }
	    catch(ClassNotFoundException ex){
	    	ex.printStackTrace();
	    }
	    catch(IOException ex){
	    	ex.printStackTrace();
	    }
	}

}
